package com.atm.atmsys.controller.YinLianController;

import com.atm.atmsys.Service.AccountService;
import com.atm.atmsys.Service.AtmService;
import com.atm.atmsys.Service.TransactionService;
import com.atm.atmsys.dto.*;
import com.atm.atmsys.entity.PageResult;
import com.atm.atmsys.utils.Result;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

import static org.apache.ibatis.ognl.OgnlOps.doubleValue;

@RestController
@RequestMapping("/Usertransaction")
@Slf4j
public class UserTransactionController {

    @Autowired
    HttpServletRequest request;
    @Autowired
    AtmService atmService;
    @Autowired
    AccountService accountService;
    @Autowired
    TransactionService transactionService;



    //删除指定ID的交易记录
    @DeleteMapping("/deleteTransaction/{id}")
    @ApiOperation("删除指定ID的交易记录")
    public Result deleteTransaction(@PathVariable int id) {
        log.info("删除交易记录");
        transactionService.deleteTransaction(id);
        return Result.success();
    }

    //查询所有交易记录
    @GetMapping("/page")
    @ApiOperation("分页查询交易记录")
    public Result<PageResult> page(TransactionPageQueryDTO transactionPageQueryDTO){
            log.info("交易记录分页查询，参数为：{}",transactionPageQueryDTO);
            PageResult pageResult=transactionService.pageQuery(transactionPageQueryDTO);
            return Result.success(pageResult);


    }


    //根据卡号查询所有交易记录
    @GetMapping("/pageByCardNo")
    @ApiOperation("分页查询指定卡号的交易记录")
    public Result<PageResult> pageByCardNo(TransactionPageByCardNo transactionPageByCardNo){
        log.info("交易记录分页查询，参数为：{}",transactionPageByCardNo);
        PageResult pageResult=transactionService.pageByCardNo(transactionPageByCardNo);
        return Result.success(pageResult);

    }

}
